package com.sls.web.manager.action.game;

import javax.annotation.Resource;

import com.sls.web.manager.action.SuperAction;
import com.sls.web.manager.common.Constants;
import com.sls.web.manager.execption.ManagerException;
import com.sls.web.manager.game.pojo.ProvinceInfo;
import com.sls.web.manager.game.service.ProvinceService;
import com.sls.web.manager.page.Pagination;

public class ProvinceAction extends SuperAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Resource(name = "provinceService")
	private ProvinceService provinceService;

	private ProvinceInfo provinceInfo;
	private ProvinceInfo proQuery;

	private Pagination<ProvinceInfo> page;
	private String id;
	private String provinceName;

	/**
	 * 新增页面跳转
	 * 
	 * @return
	 */
	public String toAdd() {
		return "province_input";
	}

	/**
	 * 记录新增
	 * 
	 * @return
	 */
	public String add() {
		try {
			provinceService.addProvinceInfo(provinceInfo, getCurrentOperator());
			redirectionUrl = "province!list.htm";
		} catch (ManagerException e) {
			flag = false;
			addActionError(e.getMessage());
		}
		return SUCCESS;
	}
	
	/**
	 * 编辑页面跳转
	 * 
	 * @return
	 */
	public String toEdit() {
		try {
			provinceInfo = provinceService.queryById(id, getCurrentOperator());
		} catch (ManagerException e) {
			flag = false;
			addActionError(e.getMessage());
		}
		return "province_edit";
	}

	/**
	 * 记录更新
	 * 
	 * @return
	 */
	public String edit() {
		try {
			provinceService
					.editProvinceInfo(provinceInfo, getCurrentOperator());
		} catch (ManagerException e) {
			flag = false;
			addActionError(e.getMessage());
		}
		return list();
	}

	/**
	 * 分页展示
	 * 
	 * @return
	 */
	public String list() {
		if (proQuery == null) {
			proQuery = new ProvinceInfo();
			proQuery.setCurrentPage(Constants.INIT_CURRENTPAGE);
			proQuery.setPageSize(Constants.INIT_PAGESIZE);
		}
		if (provinceInfo != null) {
			provinceName = provinceInfo.getProvinceName();
			proQuery.setProvinceName(provinceName);
		}
		
		try {
			page = this.provinceService.queryProPagination(proQuery,
					getCurrentOperator());
		} catch (ManagerException e) {
			this.addActionError(e.getMessage());
		}
		return LIST;
	}

	public ProvinceInfo getProvinceInfo() {
		return provinceInfo;
	}

	public void setProvinceInfo(ProvinceInfo provinceInfo) {
		this.provinceInfo = provinceInfo;
	}

	public Pagination<ProvinceInfo> getPage() {
		return page;
	}

	public void setPage(Pagination<ProvinceInfo> page) {
		this.page = page;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getProvinceName() {
		return provinceName;
	}

	public void setProvinceName(String provinceName) {
		this.provinceName = provinceName;
	}

	public ProvinceInfo getProQuery() {
		return proQuery;
	}

	public void setProQuery(ProvinceInfo proQuery) {
		this.proQuery = proQuery;
	}

}
